package com.michael.demos.ddd.springboot.adapters.in;

import com.michael.demos.ddd.springboot.common.WebAdapter;
import com.michael.demos.ddd.springboot.domains.Account;
import com.michael.demos.ddd.springboot.domains.Money;
import com.michael.demos.ddd.springboot.ports.in.SendMoneyUseCase;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@WebAdapter
@RestController
@RequiredArgsConstructor
class SendMoneyController {

	private final SendMoneyUseCase sendMoneyUseCase;

	@PostMapping(path = "/accounts/send/{sourceAccountId}/{targetAccountId}/{amount}")
	void sendMoney(
			@PathVariable("sourceAccountId") Long sourceAccountId,
			@PathVariable("targetAccountId") Long targetAccountId,
			@PathVariable("amount") Long amount
	) {

		SendMoneyUseCase.SendMoneyCommand command = new SendMoneyUseCase.SendMoneyCommand(
				new Account.AccountId(sourceAccountId),
				new Account.AccountId(targetAccountId),
				Money.of(amount)
		);

		sendMoneyUseCase.sendMoney(command);
	}
}
